package com.IO;

import sun.reflect.generics.tree.Tree;

import java.io.*;
import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) throws IOException {
        sort();
    }

    private static void sort() throws IOException {
        TreeSet<Student> set=new TreeSet<Student>(new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                int num=s2.sum()-s1.sum();
                int num2=num==0?s1.getYuwen()-s2.getYuwen():num;
                int num3=num2==0?s1.getShuxue()-s2.getShuxue():num2;
                int num4=num3==0?s1.getName().compareTo(s2.getName()):num3;
                return num4;
            }
        });
        Student stu1=new Student("张三",88,89,90);
        Student stu2=new Student("李四",78,79,80);
        Student stu3=new Student("王五",68,69,70);
        Student stu4=new Student("麻六",58,59,60);
        Student stu5=new Student("苏七",48,80,94);
        Student stu6=new Student("王八",48,79,95);
        set.add(stu1);
        set.add(stu2);
        set.add(stu3);
        set.add(stu4);
        set.add(stu5);
        set.add(stu6);
        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\下载\\file\\file2\\student.txt"));
        for (Student stu:set) {
            StringBuilder sb=new StringBuilder();
            sb.append(stu.getName()).append(",").append(stu.getShuxue()).append(",").append(stu.getYuwen()).append(",").append(stu.getYingyu());
            bw.write(sb.toString()+"    "+stu.sum());
            bw.newLine();
            bw.flush();
        }
        bw.close();

    }
}
